## Figure A6

rm(list=ls())
library(dplyr)
library(haven)

setwd("~/Dropbox/Paraguay/1_data/7_replication_dataverse")

# rural collective action data
#land data
landinv <- read_dta("data/landinv.dta")

## Create aggregate dataset
landinv <- landinv %>%
  
  # Select: year % land invasions
  dplyr::select(year, linv, linv_b, peasfam, hectares) %>%
  # Group by year
  dplyr::group_by(year) %>%
  # Aggregate: land invasions
  dplyr::summarise(linv = sum(linv), linv_b = sum(linv_b), peasfam = sum(peasfam), hectares = sum(hectares))


## (a) Land Invasions

pdf(file = "figures/figureA6a.pdf")

# Create base plot 
li.plot.i <- plot(linv ~ year, data = landinv, 
                  type = "h", 
                  lty = 1,
                  lwd = 8.5, 
                  cex.lab = 1.15, 
                  col = "darkgrey", 
                  axes = FALSE, 
                  xlim = c(1950, 2005), 
                  ylim = c(0, 90), 
                  xlab = "Year", 
                  ylab = "Peasant Land Invasions", 
                  frame.plot = FALSE)
# Line
abline(v = 1989, col = "darkred", lty = 2, lwd = 2)
# Axes
axis(side = 1, at = seq(1950, 2005, 5), cex.axis = 1.15)
axis(side = 2, at = seq(0, 90, 30), cex.axis = 1.15)

li.plot.i
dev.off()


## (b) Land Invasions (dummy)

pdf(file = "figures/figureA6b.pdf")

# Create base plot 
li.plot.b <- plot(linv_b ~ year, data = landinv, 
                  type = "h", 
                  lty = 1,
                  lwd = 8.5, 
                  cex.lab = 1.15, 
                  col = "darkgrey", 
                  axes = FALSE, 
                  xlim = c(1950, 2005), 
                  ylim = c(0, 20), 
                  xlab = "Year", 
                  ylab = "Municipalities with a Land Invasion", 
                  frame.plot = FALSE)
# Line
abline(v = 1989, col = "darkred", lty = 2, lwd = 2)
# Axes
axis(side = 1, at = seq(1950, 2005, 5), cex.axis = 1.15)
axis(side = 2, at = seq(0, 20, 5), cex.axis = 1.15)

li.plot.b
dev.off()


## (c) Peasant Invaders

pdf(file = "figures/figureA6c.pdf")

# Create base plot 
li.plot.p <- plot(peasfam ~ year, data = landinv, 
                  type = "h", 
                  lty = 1,
                  lwd = 8.5, 
                  cex.lab = 1.15, 
                  col = "darkgrey", 
                  axes = FALSE, 
                  xlim = c(1950, 2005), 
                  ylim = c(0, 25000), 
                  xlab = "Year", 
                  ylab = "Invader Peasants", 
                  frame.plot = FALSE)
# Line
abline(v = 1989, col = "darkred", lty = 2, lwd = 2)
# Axes
axis(side = 1, at = seq(1950, 2005, 5), cex.axis = 1.15)
axis(side = 2, at = seq(0, 24000, 6000), cex.axis = 1.15)

li.plot.p
dev.off()


## (d) Invaded Hectares

pdf(file = "figures/figureA6d.pdf")

# Create base plot 
li.plot.h <- plot(hectares ~ year, data = landinv, 
                  type = "h", 
                  lty = 1,
                  lwd = 8.5, 
                  cex.lab = 1.15, 
                  col = "darkgrey", 
                  axes = FALSE, 
                  xlim = c(1950, 2005), 
                  ylim = c(0, 360000), 
                  xlab = "Year", 
                  ylab = "Invaded Hectares", 
                  frame.plot = FALSE)
# Line
abline(v = 1989, col = "darkred", lty = 2, lwd = 2)
# Axes
axis(side = 1, at = seq(1950, 2005, 5), cex.axis = 1.15)
axis(side = 2, at = seq(0, 360000, 90000), cex.axis = 1.15)

li.plot.h
dev.off()



